package com.linkage.yninterface.process.processClass;

import java.util.HashMap;

import com.linkage.yninterface.db.DB;
import com.linkage.yninterface.process.process;
import com.linkage.yninterface.process.processMapInfo;
import com.linkage.yninterface.process.processPara;
import com.linkage.yninterface.process.processResult;
import com.linkage.yninterface.util.sysConst;
import com.linkage.yninterface.util.sysUtil;
import com.linkage.yninterface.util.config.operationconfig.OperationConf;

/**
 * <p>
 * Title: yun nan CRM interface
 * </p>
 * 
 * <p>
 * Description:
 * </p>
 * 
 * <p>
 * Copyright: Copyright (c) 2010
 * </p>
 * 
 * <p>
 * Company: linkage
 * </p>
 * 
 * @author weib
 * @version 1.0
 */
public class processcustomer extends process {

	private DB db = new DB(sysConst.mainDBJNDI);

	public processResult checkServiceName(processPara pp) throws Exception {
		HashMap hm = pp.getParseFields();

		String username = ((processMapInfo) hm.get(".username")).getValue();
		String servicetype = ((processMapInfo) hm.get(".servicetype"))
				.getValue();

		String hash = sysUtil.getHash(username);
		if ((!servicetype.equals("201") && !servicetype.equals("301") && !servicetype
				.equals("302")) || OperationConf.isPhone(username) == -1) {
			String sql = "select * from m_customer" + hash
					+ " where customername = '" + username + "'";
			if (db.isExist(sql))
				return new processResult(sysConst.resultCode5,
						sysConst.reaultDes5);
			else
				return new processResult(sysConst.resultCode6,
						sysConst.reaultDes6);

		} else {

			String sql = "select * from b_broadband_user" + hash
					+ " where username = '" + username + "'";

			if (servicetype.equals("201") || servicetype.equals("301")) {
				sql += " and servicetype in (201,301)";
			} else if (servicetype.equals("302")) {
				sql += " and servicetype =302";
			}

			if (db.isExist(sql))
				return new processResult(sysConst.resultCode5,
						sysConst.reaultDes5);
			else
				return new processResult(sysConst.resultCode6,
						sysConst.reaultDes6);
		}
	}
}
